#include<stdio.h>

int max(int a,int b)
{
	int max=a>b?a:b;
	return max;
}
int main()
{
	int sign,i1,i2,i3,i4,n,x,y,h;
	int z[11][11]={0},a[11][11][11][11]={0};
	scanf("%d",&n);
	do
	{
		scanf("%d %d %d",&x,&y,&h);
		z[x][y]=h;
	}while(x||y||h);
	for(i1=1;i1<=n;i1++)
	{
		for(i2=1;i2<=n;i2++)
		{
			for(i3=1;i3<=n;i3++)
			{
				for(i4=1;i4<=n;i4++)
				{
					a[i1][i2][i3][i4]=max(max(a[i1-1][i2][i3][i4-1],a[i1-1][i2][i3-1][i4]),max(a[i1][i2-1][i3][i4-1],a[i1][i2-1][i3-1][i4]))+z[i1][i2]+z[i3][i4];
					if(i1==i3&&i2==i4) a[i1][i2][i3][i4]-=z[i1][i2];
				}
			}
		}
	}
	printf("%d",a[n][n][n][n]);
	return 0;
}
